﻿Imports System.Xml
Imports System.ServiceModel.Syndication
Imports DataModel

Public Class Import
  Public Sub ImportSessions(ByVal conference As ConferenceListModel.Conference, ByVal verifyLinks As Boolean)
    Try
      BuildListRSS("http://channel9.msdn.com/posts/pdc2008/RSS/Default.aspx", conference, verifyLinks)

    Catch ex As Exception

    End Try

  End Sub

  Private Sub BuildListRSS(ByVal RSSFeedURL As String, ByVal conference As ConferenceListModel.Conference, ByVal verifyLinks As Boolean)

    Dim reader As XmlReader = XmlReader.Create(RSSFeedURL)
    Dim formatter As New Rss20FeedFormatter()

    If formatter.CanRead(reader) = False Then
      Return

    End If

    formatter.ReadFrom(reader)
    reader.Close()
    'Dim ls = New Generic.List(Of Session)

    For Each feed In formatter.Feed.Items
      'Dim x As XElement = XElement.Parse(feed.ElementExtensions(5).GetReader().ReadOuterXml)

      If feed.Id.EndsWith("/") Then
      Else
        Dim code As String = feed.Id.Substring(feed.Id.LastIndexOf("/"c) + 1, feed.Id.LastIndexOf("."c) - 1 - feed.Id.LastIndexOf("/"c))
        'ls.Add(New Session() With {.Title = feed.Title.Text, .Code = code})
        Dim s As New ConferenceListModel.Session
        s.SessionID = Guid.NewGuid
        s.ConferenceID = conference.ConferenceID
        s.SessionTitle = feed.Title.Text
        s.SessionCode = code
        s.SessionDTTM = feed.PublishDate.DateTime
        s.SessionDescription = Left(feed.Summary.Text, 2000)


        s.SessionURL = conference.RootSessionURL & code
        s.WMVHighMediaURL = Helpers.Resources.GetResourceURL(conference.RootVideoURL & "WMV-HQ/", code, "wmv", "WMV-HQ", verifyLinks)
        s.WMVMediaURL = Helpers.Resources.GetResourceURL(conference.RootVideoURL & "WMV/", code, "wmv", "WMV", verifyLinks)
        s.MP4MediaURL = Helpers.Resources.GetResourceURL(conference.RootVideoURL & "MP4/", code, "mp4", "MP4", verifyLinks)
        s.PowerPointMediaURL = Helpers.Resources.GetResourceURL(conference.RootVideoURL & "PPTX/", code, "pptx", "PPTX", verifyLinks)

        s.ZuneMediaURL = Helpers.Resources.GetResourceURL(conference.RootVideoURL & "ZUNE/", code, "wmv", "Zune", verifyLinks)
        s.SourceCodeURL = Helpers.Resources.GetResourceURL(conference.RootVideoURL & "ZIP/", code, "zip", "ZIP", verifyLinks)

        conference.Sessions.Add(s)


        'If WMVHQCheckBox.Checked Then
        'sb.AppendLine(GetResourceLink("http://mschnlnine.vo.llnwd.net/d1/pdc08/WMV-HQ/", code, "wmv", "WMV-HQ", verifyLink))
        'End If
        'If WMVCheckBox.Checked Then
        'sb.AppendLine(GetResourceLink("http://mschnlnine.vo.llnwd.net/d1/pdc08/WMV/", code, "wmv", "WMV", verifyLink))
        'End If
        'If ZuneCheckBox.Checked Then
        'sb.AppendLine(GetResourceLink("http://mschnlnine.vo.llnwd.net/d1/pdc08/ZUNE/", code, "wmv", "Zune", verifyLink))
        'End If
        'If MP4CheckBox.Checked Then
        'sb.AppendLine(GetResourceLink("http://mschnlnine.vo.llnwd.net/d1/pdc08/MP4/", code, "mp4", "MP4", verifyLink))
        'End If
        'If ZIPCheckBox.Checked Then
        'sb.AppendLine(GetResourceLink("http://mschnlnine.vo.llnwd.net/d1/pdc08/ZIP/", code, "zip", "ZIP", verifyLink))
        'End If
        'If PPTXCheckBox.Checked Then
        'sb.AppendLine(GetResourceLink("http://mschnlnine.vo.llnwd.net/d1/pdc08/PPTX/", code, "pptx", "PPTX", verifyLink))
        'End If

      End If

    Next

    Return

  End Sub

End Class
